class Solution(object):
    def dfs(self, root, target, res, path):
        #空节点，直接返回
        if root is None:
            return
        
        #叶子节点，符合条件，则返回
        target = target - root.val

        if root.left is None and root.right is None and target == 0:
            res.append(path + [root.val])
            return

        path.append(root.val)
        self.dfs(root.left, target, res, path)
        self.dfs(root.right, target, res, path)
        path.pop()

    def pathSum(self, root, target):
        """
        :type root: TreeNode
        :type target: int
        :rtype: List[List[int]]
        """
        res = []
        path = []
        self.dfs(root, target, res, path)
        return res
